package com.xuelang.pipeline.client.pipeline.enums;

import lombok.Getter;

/**
 * @author liuyuan.ly
 * @since 2024/6/27 14:39
 */
@Getter
public enum TaskInstanceEnum {
    notStart(0, "notStart"),
    running(1, "running"),
    success(2, "success"),
    failed(3, "fail"),
    waiting(4, "waiting"),
    timeout(5, "timeout"),
    unknown(6, "unknown"),
    terminated(7, "terminated");

    /** pod
     * notStart(0, "notStart"),
     *     running(1, "Running"),
     *     success(2, "Succeeded"),
     *     fail(3, "Failed"),
     *     unknown(6, "Unknown"),
     *     completed(8, "Completed");
     */

    private final Integer key;
    private final String value;

    TaskInstanceEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public static TaskInstanceEnum fromValue(String value) {
        for (TaskInstanceEnum taskInstanceEnum : TaskInstanceEnum.values()) {
            if (taskInstanceEnum.value.equals(value)) {
                return taskInstanceEnum;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + value);
    }

    public static TaskInstanceEnum fromKey(Integer key) {
        for (TaskInstanceEnum taskInstanceEnum : TaskInstanceEnum.values()) {
            if (taskInstanceEnum.key.equals(key)) {
                return taskInstanceEnum;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + key);
    }
}
